package com.sq.goodline.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import com.sq.goodline.interceptor.AccessTokenInterceptor;

@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {

	@Bean
	public AccessTokenInterceptor accessTokenInterceptor() {
		return new AccessTokenInterceptor();
	}
	 
	
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(accessTokenInterceptor()).addPathPatterns("/openapi/**");

		super.addInterceptors(registry);
	}
	
	/*** 
     * 配置静态资源访问拦截 
     * @param registry 
     */ 
    public void addResourceHandlers(ResourceHandlerRegistry registry){
        registry.addResourceHandler("doc.html") 
                .addResourceLocations("classpath:/META-INF/resources/"); 
        registry.addResourceHandler("/webjars/**") 
                .addResourceLocations("classpath:/META-INF/resources/webjars/"); 
    } 
	
}
